package pers.mydb.connection;

import pers.mydb.connection.configuration.Configuration;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 数据库连接
 */
public class DBConnection {

    /**
     * 获取连接
     * @param configuration 连接配置
     * @return 数据库连接
     */
    public static Connection getConfiguration(Configuration configuration){
        Connection connection = null;
        try {
            // 获取数据库连接
            Class.forName(configuration.getDbDriverClass());
            connection = DriverManager.getConnection(configuration.getDbUrl(), configuration.getDbUser(),
                    configuration.getDbPassword());
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
        return connection;
    }


}
